﻿using System;
using System.Collections.Generic;
using System.Text;
using DrvFRLib;
using CashResource;
using CashCommon;

namespace CashDriver
{
    /// <summary>
    /// Класс-оболочка, для драйвера FRK. 
    /// </summary>
    public sealed class FrkDrv
    {
        #region Методы драйвера

        public void AddLD()
        {
            try
            {
                _drvFRClass.AddLD();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.AddLD, err);
            }
        }
        /// <summary>
        /// Вызов формы "Настройка свойств" для настройки параметров портов ПК для связи с ККМ.
        /// </summary>
        public void ShowProperties()
        {
            try
            {
                _drvFRClass.ShowProperties();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.ShowProperties, err);
            }
        }
        /// <summary>
        /// Выдача звукового сигнала для ККМ
        /// </summary>
        public void Beep()
        {
            try
            {
                _drvFRClass.Beep();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.Beep, err);
            }
        }
        /// <summary>
        /// Метод подает на принтер чеков команду «Отрезать чек»
        /// </summary>
        public void CutCheck()
        {
            try
            {
                _drvFRClass.CutType = true;
                _drvFRClass.CutCheck();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.CutCheck, err);
            }
        }
        public void OpenCheck()
        {
            try
            {
                _drvFRClass.OpenCheck();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.OpenCheck, err);
            }
        }
        public void Connect()
        {
            try
            {
                _drvFRClass.Connect();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.Connect, err);
            }
        }
        public void Sale()
        {
            try
            {
                _drvFRClass.Sale();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.Sale, err);
            }
        }
        public int CloseCheck()
        {
            try
            {
                return _drvFRClass.CloseCheck();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.CloseCheck, err);
            }
        }
        public void CancelCheck()
        {
            try
            {
                _drvFRClass.CancelCheck();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.CancelCheck, err);
            }
        }
        public void PrintString()
        {
            try
            {
                _drvFRClass.PrintString();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.PrintString, err);
            }
        }
        public void ReturnSale()
        {
            try
            {
                _drvFRClass.ReturnSale();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.ReturnSale, err);
            }
        }
        public void PrintReportWithCleaning()
        {
            try
            {
                _drvFRClass.PrintReportWithCleaning();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.PrintReportWithCleaning, err);
            }
        }
        public void PrintReportWithoutCleaning()
        {
            try
            {
                _drvFRClass.PrintReportWithoutCleaning();
            }
            catch (Exception err)
            {
                throw new ECashDriver(MessageType.AllertLog, DriverError.PrintReportWithoutCleaning, err);
            }
        }
        public void ContinuePrint()
        { 
            try 
	        {
                _drvFRClass.ContinuePrint();
	        }
	        catch (Exception err)
	        {
                throw new ECashDriver(MessageType.AllertLog, DriverError.ContinuePrint, err);
	        }
            
        }

        #endregion  

        #region Свойства драйвера

        /// <summary>
        /// Пароль
        /// </summary>
        public int Password
        {
            get
            {
                return _drvFRClass.Password;
            }
            set
            {
                _drvFRClass.Password = value;            
            }
        }
        /// <summary>
        /// Тип открываемого документа/чека. Диапазон значений: 0…3: «0» - продажа, «1» - покупка, «2» - возврат продажи, «3» - возврат покупки.
        /// </summary>
        public int CheckType 
        { 
            get
            {
                return _drvFRClass.CheckType;
            }
            set
            {
                _drvFRClass.CheckType = value;
            } 
        
        }
        /// <summary>
        ///0  36 ШТРИХ-ФР-Ф
        ///1  36 ШТРИХ-ФР-Ф (Казахстан)
        ///2  24 ЭЛВЕС-МИНИ-ФР-Ф
        ///3  20 ФЕЛИКС-Р Ф
        ///4  36 ШТРИХ-ФР-К
        ///5  40 ШТРИХ-950К
        ///6  32 ЭЛВЕС-ФР-К
        ///7  50 ШТРИХ-МИНИ-ФР-К
        ///8  36 ШТРИХ-ФР-Ф (Белоруссия)
        ///9  48 ШТРИХ-КОМБО-ФР-К версии 1
        ///10 40 Фискальный блок Штрих-POS-Ф
        ///11 40 Штрих950K версия 2
        ///12 40 ШТРИХ-КОМБО-ФР-К версии 2
        ///13 50 ШТРИХ-МИНИ-ФР-К 2
        /// </summary>
        public int UModel 
        {
            get
            {
                return _drvFRClass.UModel;
            }
        }
        public decimal Summ1 { get { return _drvFRClass.Summ1; } set { _drvFRClass.Summ1 = value; } }
        public decimal Summ2 { get { return _drvFRClass.Summ2; } set { _drvFRClass.Summ2 = value; } }
        public decimal Summ3 { get { return _drvFRClass.Summ3; } set { _drvFRClass.Summ3 = value; } }
        public decimal Summ4 { get { return _drvFRClass.Summ4; } set { _drvFRClass.Summ4 = value; } }
        public decimal Price 
        {
            get
            {
                return _drvFRClass.Price;
            }
            set
            {
                _drvFRClass.Price = value;
            }
        
        }
        public double Quantity 
        { 
            get
            {
                return _drvFRClass.Quantity;
            }
            set
            {
                _drvFRClass.Quantity = value;
            }
        }
        public int Department { get { return _drvFRClass.Department; } set { _drvFRClass.Department = value;} }
        public int Tax1 { get { return _drvFRClass.Tax1; } set { _drvFRClass.Tax1 = value; } }
        public int Tax2 { get { return _drvFRClass.Tax2; } set { _drvFRClass.Tax2 = value; } }
        public int Tax3 { get { return _drvFRClass.Tax3; } set { _drvFRClass.Tax3 = value; } }
        public int Tax4 { get { return _drvFRClass.Tax4; } set { _drvFRClass.Tax4 = value; } }
        public string StringForPrinting { get { return _drvFRClass.StringForPrinting; } set { _drvFRClass.StringForPrinting = value; } }
        public decimal Change { get { return _drvFRClass.Change; } }
        public double DiscountOnCheck { get { return _drvFRClass.DiscountOnCheck; } set { _drvFRClass.DiscountOnCheck = value; } }
        public bool UseReceiptRibbon { get { return _drvFRClass.UseReceiptRibbon; } set { _drvFRClass.UseReceiptRibbon = value; } }
        public bool UseJournalRibbon { get { return _drvFRClass.UseJournalRibbon; } set { _drvFRClass.UseJournalRibbon = value; } }
        public int OpenDocumentNumber { get { return _drvFRClass.OpenDocumentNumber; }  }

        #endregion

        private void t()
        {
            //_drvFRClass.UseReceiptRibbon
            //_drvFRClass.OpenDocumentNumber

        }

        #region Создание экземпляра класса
        
        // Получение экземпляра 
        public static FrkDrv Inst
        {
            get
            {
                if (_frkDrv == null)
                {
                    lock (_syncRoot)
                    {
                        _frkDrv = new FrkDrv();
                        return _frkDrv;
                    }
                }
                return _frkDrv;
            }
        }
        
        /// <summary>
        /// Закрытый конструктор
        /// </summary>
        private FrkDrv() 
        {
            _drvFRClass = new DrvFRClass();
        }
        private static object _syncRoot = new Object();


        #endregion

        // Private
        private static FrkDrv _frkDrv;
        private DrvFRClass _drvFRClass;
    }
}
